package com.niit.project.controller;

import com.niit.project.entity.UserGoods;
import com.niit.project.service.UserGoodsService;
import com.niit.project.service.impl.UserGoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;

//这个方法本来想用来实现搜索商品的,但后来不知道什么原因,一直不起作用,所以就放弃了
@WebServlet(name = "ShowUserGoodsInfo", value = "/ShowUserGoodsInfo")
public class ShowUserGoodsInfo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取并强转从前端获取的id信息
        Integer id = Integer.valueOf(request.getParameter("id"));
        UserGoodsService userGoodsService = new UserGoodsServiceImpl();
        //通过id查找相关商品的所有信息
        UserGoods userGoods = userGoodsService.selectGoodsById(id);
        //将查询到的信息存入请求中
        request.setAttribute("userGoods",userGoods);
        //转发
        request.getRequestDispatcher("/UpdateUserGoods.jsp").forward(request,response);
    }
}
